package part14;

/**
 * @author wcj
 * @Date 2021/5/25 18:54
 * @Version 1.0
 */
public class Part143 {

    public static void printInfo(Class cc) {
        System.out.println("class name:" + cc.getName() + ",is interface:" + cc.isInterface());
        System.out.println("simple name:" + cc.getSimpleName());
        System.out.println("Canonical name:" + cc.getCanonicalName());
    }

    /**
     * class.forName()获取对象引用，需要传递全限定名即包含包名
     * Class类中包含的方法
     * @param args
     */
    public static void main(String[] args) {
        Class c = null;
        try {
            c = Class.forName("part14.FancyTony");
        } catch (ClassNotFoundException e) {
            System.out.println("can't find FancyTony");
            System.exit(1);
        }

        printInfo(c);

        for (Class face : c.getInterfaces()) {
            printInfo(face);
        }

        Class up = c.getSuperclass();
        Object obj = null;
        try {
            obj = up.newInstance();
        } catch (InstantiationException e) {
            System.out.println("can't instance");
            System.exit(1);
        } catch (IllegalAccessException e) {
            System.out.println("can't access");
            System.exit(1);
        }

        printInfo(obj.getClass());
    }
}

interface HasBatteries {
}

interface Waterproof {
}

interface Shoots {
}

class Tony {
    Tony() {
    }

    Tony(int i) {
    }
}

class FancyTony extends Tony implements HasBatteries, Waterproof, Shoots {
    public FancyTony() {
        super(1);
    }
}
